package com.example.myspringboot.controller;

import com.example.myspringboot.bean.Teacher;
import com.example.myspringboot.bean.User;
import com.example.myspringboot.dao.TeacherMapper;
import com.example.myspringboot.dao.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
public class UserController {
    @Autowired
    private UserMapper userMapper;
    @Autowired
    private TeacherMapper teacherMapper;           //自动装配，每个都要写

    @RequestMapping("/login")
    public String checklogin(Model model, User user) {
        User user1 = userMapper.checklogin(user);
        if (user1 != null) {
            return "redirect:/tomain";
        } else {
            return "index.html";
        }
    }

    //主界面
    @RequestMapping("/tomain")
    public String tomain(Model model) {
        List<Teacher> list = teacherMapper.queryAllTea();
        model.addAttribute("list", list);
        return "main";
    }
}
